export class MixStore extends DataStore {
    stores = []
    name = 'MixStore'
  
    constructor(stores = []) {
      super()
      this.stores = stores
    }
  
    setItem(key, value) {
      this.stores.forEach(s => {
        if (s.test) {
          if (s.test(key, value)) {
            s.setItem(key, value)
          }
        } else {
          s.setItem(key, value)
        }
      })
    }
  
    getItem(key) {
      for (let i = 0; i < this.stores.length; i++) {
        const s = this.stores[i]
        if (s.test) {
          if (s.test(key)) {
            const v = s.getItem(key)
            if (v !== undefined) {
              return v
            }
          }
        } else {
          const v = s.getItem(key)
          if (v !== undefined) {
            return v
          }
        }
      }
    }
  
    getKeys() {
      let keys = []
      this.stores.forEach(s => {
        keys = [...keys, s.getKeys()]
      })
      const tmp = {}
      keys.forEach(key => {
        tmp[key] = 0
      })
      return Object.keys(tmp)
    }
  
    removeItem(key) {
      this.stores.forEach(s => {
        s.removeItem(key)
      })
    }
  
    clear() {
      this.stores.forEach(s => {
        s.clear()
      })
    }
  }
  